const menuItems = [
    {
        key: 'sys',
        label: '系统管理',
        children: [
            { key: 'sys/menu', label: '菜单管理' },
            { key: 'sys/role', label: '角色管理' },
        ],
    },
    {
        key: 'shop',
        label: '商城系统',

        children: [
            { key: 'shop/banner', label: 'banner' },
            {
                key: 'shop/category',
                label: '商品分类',
            },
            {
                key: 'shop/goods',
                label: '商品管理',
            },
        ],
    },
    {
        key: 'oa',
        label: 'OA办公系统',

        children: [
            { key: 'oa/list', label: '回复管理' },
            { key: 'oa/lg', label: '日志管理' },
            { key: 'oa/reply', label: '日志回复' },
        ],
    },
]
/**
 * 根据key查找对应label
 *   arr instanceOf  Array
 *   Object.Prototype.toString().call() === [object Array]
 * @param {*} list
 * @param {*} key
 */
const findLabelByKey = (list, key) => {
    for (let i = 0; i < list.length; i++) {
        let item = list[i] // 菜单项
        if (item.key === key) {
            return item.label
        }

        if (item.children && Array.isArray(item.children)) {
            // 递归调用
            const subLabel = findLabelByKey(item.children, key)
            if (subLabel) {
                return subLabel
            }
        }
    }
}

const label = findLabelByKey(menuItems, 'shop')
console.log(label)
